var curSearchType = "";
var curText = "";
function searchArticles(searchType, text, pageNum){
  var param = {};
  param.pageSize=global.pageSize;
  param.pageNum = pageNum;
  param.searchType = searchType;
  param.text = text;
  curSearchType = searchType;
  curText = text;
  // curFolderName = folderName;
  postAjaxJsonHttpRequst(global.ims + 'search/page', param, null, searchArticleCallback);
}

function searchArticleCallback(result) {
  if(curSearchType == 'es'){
    for(var i=0; i< $("#folderUl").children('li').length; i++) {
      $($("#folderUl").children('li').get(i)).removeClass("liActive");
    }
  }

  var page = {};
  page.total = result.total;
  page.currentPage = result.pageNum
  page.totalPages = result.pages;
  $('#total').html('总' +  result.total + '条');

  $(".pagination").jqPaginator({
    totalPages: page.totalPages,
    visiblePages: page.visiblePages == null? 10: page.visiblePages,
    currentPage: page.currentPage,
    totalCounts: page.total,
    onPageChange: function (num, type) {
      if(type != 'init') {
        searchArticles(curSearchType, curText, num)
      }
      $('#text').html('当前第' + num + '页');
    }
  });


  var aritclesHtml = "";
  var aritcleList = result.list;
  for(var i=0; i< aritcleList.length;i++){
    if(aritcleList[i].authors.length > 1000) {
      aritcleList[i].authors = aritcleList[i].authors.substr(0, 999);
    }
    aritclesHtml += '<li class="pic">'+ 
              '<a title="'+ aritcleList[i].contentName + '" href="detail.html?contentId=' + aritcleList[i].contentId + '" target="_blank">' +
                '<div >' +
                  '<img src="images/more.jpg" class="aritcleListImg">' + 
                  '<div class="text_content">' +
                    '<h4 class="bt">'+ aritcleList[i].contentName + '</h4>' +
                    '<div class="docsum-citation full-citation">'+
                      '<span class="docsum-authors full-authors" ><p>' + aritcleList[i].authors + '</p></span>'+
                      //'<span class="docsum-authors short-authors">Quang C, et al.</span>'+
                      '<span class="docsum-journal-citation full-journal-citation">' + aritcleList[i].citation + '</span>'+
                      '<span class="citation-part">PMID: <span class="docsum-pmid">' + aritcleList[i].contentId + '</span></span>'+
                      //'<span class="publication-type spaced-citation-item citation-part">Review.</span>'+
                    '</div>' +
                    '<p>'+ aritcleList[i].abstracts + '</p>' +
                  '</div>' +
                '</div>' +
              '</a>' +
            '</li>'
  }
  $("#articles").html(aritclesHtml);
  
}